Assistant Tool With User Approval PRO
The approval-required AssistantTools typically involve privacy, permissions, data modification, or irreversible actions, and therefore must obtain explicit user consent before execution.
When Approval Is Required
An AssistantTool must use the approval model if it meets any of the following criteria:
- Accesses user-private data (location, photos, contacts, calendar, health data, etc.)
- Triggers system permission prompts
- Modifies, deletes, or batch-writes user files
- Produces long-lasting or irreversible effects
- Requires the user to understand and confirm what will happen before execution
The purpose of approval is informed consent, not blocking functionality.
assistant_tool.json Configuration
Approval-required tools must explicitly declare approval behavior:
Key Fields
-
requireApproval: trueIndicates that the tool must enter the approval flow before execution (either manual approval or auto-approval). -
autoApprove(tool-level auto-approval permission)autoApprovedetermines whether this specific tool is allowed to be auto-approved.Auto-approval occurs only when both conditions are met:
- The user has enabled auto-approve tools in the chat preset
- The tool itself declares
autoApprove: true
As a result:
- User enables auto-approve, tool sets
autoApprove: false→ manual approval is still required - Tool sets
autoApprove: true, user has not enabled auto-approve → manual approval is still required - User enables auto-approve and tool sets
autoApprove: true→ the tool is automatically approved and executed
-
scriptEditorOnlyDetermines whether the tool is restricted to the script editor context.
The Two-Phase Approval Model
Approval-required AssistantTools always follow a two-phase model:
-
Approval Request Phase Generates the approval UI (or explanatory text in auto-approval cases).
-
Execute-With-Approval Phase Executes the actual logic after approval has been granted (manually or automatically).
These phases are implemented using two separate registration APIs.
Registering the Approval Request Function
Registration
Function Signature
Approval Request Design Principles
- The
messagemust clearly explain what will happen and why approval is required - Use user-friendly language, not implementation details
- No side effects must occur in this phase
- All real operations must be performed in the execute phase
Basic Example
Using the Preview Button
The previewButton allows users to inspect the expected outcome before approving.
Appropriate use cases include:
- File modifications (showing diffs)
- Batch edit previews
- Data export summaries
Example: File Diff Preview
Registering the Execute-With-Approval Function
Registration
Function Signature
Handling userAction
Handling rules:
- Execute real logic only if
primaryConfirmed === true secondaryConfirmed === trueusually means the user cancelled- If both values are
false, treat it as an unconfirmed or aborted flow
Example: Location Request
autoApprove and userAction Semantics
When auto-approval actually occurs (user enables auto-approve and the tool sets autoApprove: true):
- The system skips manual user interaction
- The execute phase is still invoked
userActionrepresents an equivalent of primary confirmation (e.g.primaryConfirmed: true)
Therefore, execution logic must always gate side effects on primaryConfirmed, ensuring compatibility with:
- Manual approval
- Automatic approval
- Explicit cancellation
scriptEditorProvider in Approval-Required Tools
-
If
scriptEditorOnly: true:- Both approval request and execute functions receive
scriptEditorProvider - Can be used for diffs, file access, lint inspection, etc.
- Both approval request and execute functions receive
-
If
scriptEditorOnly: false:scriptEditorProvidermay beundefined- Editor capabilities must not be assumed
Designing the Execution Message
For approval-required tools, the returned message should:
- Clearly indicate success, failure, or cancellation
- Provide structured output when appropriate
- Help the Assistant reason about the result
Examples:
Using Test Functions
Registered functions return test helpers:
These are intended for validating logic paths and return values, not for simulating real system permission dialogs.
Design Summary
- Approval exists to ensure informed user consent
autoApproveis a tool-level permission, not a global switch- Auto-approval requires both user preset and tool consent
- Never perform side effects during the approval request phase
- Always guard execution logic with
primaryConfirmed - Use previews whenever file or data changes are involved
